﻿// <copyright file="TimeFrame.cs" company="Golizza.net">Copyright (c) 2012 All Right Reserved</copyright>

namespace Sharemarker.BinaryOptionApplication.Models
{
    using Sharemarker.Common.Framework;

    /// <summary>
    /// The sign enum of time frame.
    /// </summary>
    public enum TimeFrameSign
    {
        /// <summary>
        /// The minute time frame.
        /// </summary>
        M = 1,

        /// <summary>
        /// The hour time frame.
        /// </summary>
        H = 60,

        /// <summary>
        /// The day time frame.
        /// </summary>
        D = 1440
    }

    /// <summary>
    /// The model fore Time Frame.
    /// </summary>
    public class TimeFrame : NotifyPropertyChangedBase
    {
        #region Fields

        /// <summary>
        /// The back up value for <see cref="Number"/> property.
        /// </summary>
        private int number;

        /// <summary>
        /// The back up value for <see cref="Sign"/> property.
        /// </summary>
        private TimeFrameSign sign = TimeFrameSign.M;

        /// <summary>
        /// The back up value for <see cref="Value"/> property.
        /// </summary>
        private int value;

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the Number.
        /// </summary>
        public int Number
        {
            get
            {
                return this.number;
            }

            set
            {
                if (this.number != value)
                {
                    this.number = value;
                    this.OnPropertyChanged("Number");

                    this.Value = (int)this.sign * this.number;
                }
            }
        }

        /// <summary>
        /// Gets or sets the Sign.
        /// </summary>
        public TimeFrameSign Sign
        {
            get
            {
                return this.sign;
            }

            set
            {
                if (this.sign != value)
                {
                    this.sign = value;
                    this.OnPropertyChanged("Sign");

                    this.Value = (int)this.sign * this.number;
                }
            }
        }

        /// <summary>
        /// Gets the Value.
        /// </summary>
        public int Value
        {
            get
            {
                return this.value;
            }

            private set
            {
                if (this.value != value)
                {
                    this.value = value;
                    this.OnPropertyChanged("Value");
                }
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return string.Format("{0}{1}", this.sign, this.number);
        }

        #endregion
    }
}